﻿using Windows.UI;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using com.IronOne.BoardPACWinApp.Common;
using com.IronOne.BoardPACWinApp.Helpers;
using com.IronOne.BoardPACWinApp.View.Page;
using com.IronOne.BoardPACWinApp.ViewModel;
using com.IronOne.BoardPACWinAppBO.General;
using com.IronOne.BoardPACWinAppUtil.Util;
using GalaSoft.MvvmLight.Messaging;

// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236

namespace com.IronOne.BoardPACWinApp.View.UserControl
{
    public sealed partial class MenuBottomAppBarUserControl
    {
        private readonly INavigationService _navigationService;
        private readonly AppSettingsManager _asm;

        public MenuBottomAppBarUserControl()
        {
            InitializeComponent();
            _navigationService = new NavigationService();
            _asm = new AppSettingsManager();

            Messenger.Default.Register<NotificationMessage<MessageDataModel>>(this, HandleMessages);

            var isPinned = _asm.GetAppBarPinnedStatus();
            if (isPinned)
                PinnedAppBarButton.IsChecked = true;
        }

        private void HandleMessages(NotificationMessage<MessageDataModel> mdm)
        {
            if (!mdm.Notification.Equals(MessageCodes.CURRENT_PAGE)) return;

            ResetButtons();

            switch ((string) mdm.Content.MessageData)
            {
                case "MeetingsPage":

                    #region MeetingsPage

                    CommentButton.Visibility = Visibility.Visible;
                    PastPapersButton.Visibility = Visibility.Visible;

                    #endregion

                    break;

                case "CommentsPage":

                    #region CommentsPage

                    MeetingsButton.Visibility = Visibility.Visible;
                    PastPapersButton.Visibility = Visibility.Visible;

                    #endregion

                    break;
                    
                case "PastPapersSearchPage":

                    #region PastPapersSearchPage

                    MeetingsButton.Visibility = Visibility.Visible;
                    CommentButton.Visibility = Visibility.Visible;

                    #endregion

                    break;

                case "CalenderPage":

                    #region CalenderPage

                    MeetingsButton.Visibility = Visibility.Visible;
                    CommentButton.Visibility = Visibility.Visible;
                    PastPapersButton.Visibility = Visibility.Visible;

                    #endregion

                    break;

                case "AddCommentsPage":

                    #region AddCommentsPage

                    MeetingsButton.Visibility = Visibility.Visible;
                    PastPapersButton.Visibility = Visibility.Visible;

                    #endregion

                    break;
            }
        }

        private void ResetButtons()
        {
            MeetingsButton.Visibility = Visibility.Collapsed;
            CommentButton.Visibility = Visibility.Collapsed;
            PastPapersButton.Visibility = Visibility.Collapsed;
        }

        private void PinnedAppBarButton_Checked(object sender, RoutedEventArgs e)
        {
            BasePage.PinnedAppBarButton_Checked(PinnedAppBarButton, _asm);
        }

        private void PinnedAppBarButton_Unchecked(object sender, RoutedEventArgs e)
        {
            BasePage.PinnedAppBarButton_UnChecked(PinnedAppBarButton, _asm);
        }

        private void CommentButton_Click(object sender, RoutedEventArgs e)
        {
            BasePage.CommentButton_Click(_navigationService);
        }

        private void MeetingsButton_Click(object sender, RoutedEventArgs e)
        {
            BasePage.MeetingsButton_Click(_navigationService);
        }

        private void PastPapersButton_Click(object sender, RoutedEventArgs e)
        {
            _navigationService.NavigateTo(typeof (PastPapersSearchPage));
        }

        
        /*private void LastViewedButton_Click(object sender, RoutedEventArgs e)
        {
        }*/

        /*private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            SendFlyoutOpenMessage();
        }*/

        /*private void PaperCommentButton_Click(object sender, RoutedEventArgs e)
        {
            AddCommentsViewModel.CommentType = 0; //Paper Comments
            AddCommentsViewModel.CommentTypeHeading = "Paper Comments";
            _navigationService.NavigateTo(typeof (AddCommentsPage));

            var mdm = new MessageDataModel {MessageData = 0};
            var message = new NotificationMessage<MessageDataModel>(mdm, MessageCodes.GET_COMMENTS);
            Messenger.Default.Send(message);
        }*/

        /*private void MeetingCommentsButton_Click(object sender, RoutedEventArgs e)
        {
            AddCommentsViewModel.CommentType = 1; //Meeting Comments
            AddCommentsViewModel.CommentTypeHeading = "Meeting Comments";
            _navigationService.NavigateTo(typeof (AddCommentsPage));

            var mdm = new MessageDataModel {MessageData = 1};
            var message = new NotificationMessage<MessageDataModel>(mdm, MessageCodes.GET_COMMENTS);
            Messenger.Default.Send(message);
        }*/

        /*private void ShowHidePaperCommentButton(string msg)
        {
            PaperCommentButton.Visibility = Visibility.Visible;
        }*/

        /*private void ItemsPanelOpenButton_Click(object sender, RoutedEventArgs e)
        {
            SendFlyoutOpenMessage();
        }*/

        /*private void SendFlyoutOpenMessage()
        {
            var mdm = new MessageDataModel {MessageData = true};
            var message = new NotificationMessage<MessageDataModel>(mdm, MessageCodes.SEARCH_FLYOUT);
            Messenger.Default.Send(message);
        }*/
    }
}